package com.sig.util;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author sig
 * @since 2016-6-4 16:28:54
 */
public class CdKeyUtil {

    /**
     * 随机序列号生成器
     *
     * @param num       数量
     * @param prefixNum 前缀个数
     * @param patch     批次
     * @param suffix    尾数
     * @return
     */
    public static Set<Long> generate(int num, int prefixNum, int patch, int suffix) {
        Set<Long> keyIds = new HashSet<>();

        while (keyIds.size() < num) {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < prefixNum; i++)
                sb.append(ThreadLocalRandom.current().nextInt(9) + 1);
            sb.append(patch).append(suffix);
            keyIds.add(Long.valueOf(sb.toString()));
        }
        return keyIds;
    }
}
